import request from '@/api/index'

export interface LoginParams {
  username: string
  password: string
}


export interface LoginResponseData {
  user: {
    id: number
    user_name: string
    type: number
  }
  token: string
}

export interface UserInfo {
  id: number
  username: string
  usertype: number
}

// 通用 API 响应结构
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}
export interface UpdatePasswordParams {
  user_id: number
  old_password: string
  new_password: string
}

export function loginApi(params: LoginParams): Promise<ApiResponse<LoginResponseData>> {
  return request.post('/login', params)
}

export function registerApi(params: LoginParams): Promise<ApiResponse<null>> {
  return request.post('/register', params)
}
export function updateUserPassword(params: UpdatePasswordParams) {
  return request.post('/user/update-info', params)
}
export function getUserList() {
  return request.get('/user/list')
}
export function deleteUser(id: number) {
  return request.delete(`/user/${id}`)
}

export function upgradeToCreator(id: number) {
  return request.put(`/user/upgrade-to-creator/${id}`)
}

export function resetUserPassword(id: number) {
  return request.put(`/user/reset-password/${id}`)
}